package router

import (
	_ "project-info/src/router/ai"            // 添加AI路由
	_ "project-info/src/router/dynamicTable"  // 添加动态表格路由
	_ "project-info/src/router/gitlab"        // 添加GitLab路由
	_ "project-info/src/router/item"          // 添加项目路由
	_ "project-info/src/router/jenkins"       // 添加Jenkins路由
	_ "project-info/src/router/mcp"           // 添加MCP路由
	_ "project-info/src/router/oidc"          // 添加OIDC路由
	_ "project-info/src/router/resource"      // 添加资源路由
	_ "project-info/src/router/system"        // 添加系统路由
	_ "project-info/src/router/terminal"      // 添加终端路由
	_ "project-info/src/router/workflowRoute" // 添加工作流路由

	"project-info/src/router/variable"

	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

func AddRouter(e *gin.Engine) {
	// 配置CORS中间件
	config := cors.DefaultConfig()
	config.AllowAllOrigins = true
	config.AllowMethods = []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"}
	config.AllowHeaders = []string{"*"}
	e.Use(cors.New(config))

	// 静态文件服务
	e.Static("/static", "./upload")

	// 首页路由
	e.GET("/", func(c *gin.Context) {
		c.File("./dist/index.html")
	})

	// 初始化各模块路由
	for _, f := range variable.InitRouteFunc {
		f(e)
	}
}
